﻿using PlaceOrder_Shared.Models.Trade;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace PlaceOrder_Client.Converters
{
    internal class FilteredTradesConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var trades = value as IEnumerable<TradeHistoryRow>;
            if (trades == null) return null;

            DateTime today = DateTime.Today;

            var tempTrades = trades
                .Where(tr => tr.TradeDate.Date == today)
                .OrderByDescending(tr => tr.TradeDate)
                .ThenByDescending(tr => tr.TradeTime)
                .ToList();

            return new ObservableCollection<TradeHistoryRow>(tempTrades);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
